
//分页混入，需要自己写load函数，created必须获取数据才有效
export default {
    data() {
        return {
            page: {
                current: 1,
                size: 10,
                pages:0,
            },
            loading: true,
        };
    },
    computed: {
        noMore() {
            return (
                (this.page.current == this.page.pages || this.page.pages == 0) &&
                !this.loading
            );
        },
        disabled() {
            return this.loading || this.noMore;
        },
    },
    methods: {
       scrollCallback(e) {
            if (this.disabled) return;
            if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
              this.loading = true;
              setTimeout(() => {
                this.load();
              }, 200);
            }
          }
    },
    
    mounted() {
        window.addEventListener("scroll",this.scrollCallback)
    },
    beforeDestroy() {
        window.removeEventListener("scroll", this.scrollCallback)
    },
}